<?php
$userID = $this->auth->userid;
$topic = $this->topic;
$topic_gellary = $this->topic_gellary;



?>
<div class="container">
    <!-- start: Page Title Icon-->
    <div id="page-title-icon"></div>
    <div id="page-title-icon-inner">
        <i class="ico-google-maps ico-white"></i>
    </div>
    <!-- end: Page Title Icon-->
    <!-- start: Page Title -->
    <section id="page-title">
        <h2><span>Sửa sản phẩm</span></h2>
    </section>
</div>
<div id="wrapper" class="white-wrapper">

    <!-- start: Container -->
    <div class="container">

        <div class="sixteen columns">
            <form method="post" action="<?php echo $this->url('frontendtopic',array('action'=>'edit','id'=>$topic->id)) ?>">

                <div class="field">
                    <label>Tiêu đề:</label>
                    <input type="text" name="title" class="text" value="<?php echo $topic->title ?>">
                </div>

                <div class="field">
                    <input type="hidden" name="id" value="<?php echo $topic->id ?>">
                    <input type="hidden" name="user_id" class="text" value="<?php echo $topic->user_id; ?>">
                </div>

                <div class="field">
                    <label>Ảnh: </label>
                    <input type="hidden" id="images_thumb" name="images" class="text" value="<?php echo $topic->images ?>">
                    <img style="width: 100px;height: 100px" src="<?php echo $topic->images ?>" id="images" >
                </div>


                <div class="field">
                    <input id="file_upload" name="file_upload" type="file" multiple="true">
                </div>
                <div class="sixteen column">
                    <div  class="flickr-widget" id="img_content">
                        <?php
                            foreach($topic_gellary as $gall){
                                ?>
                                <div class="flickr_badge_image_upload two columns"><input type="hidden" name="gel[]" value="<?php echo $gall->link; ?>"> <img src="<?php echo $gall->link; ?>" ><input type="button" class="btn_set_thumbnail" thumb="<?php echo $gall->link; ?>" value="Set Thumbnail"><input type="button" class="btn_delete_img" value="Delete"> </div>
                        <?php
                            }
                        ?>
                    </div>
                </div>
                <div class="clearfix"></div>
                <div class="field" style="margin-top: 10px;">
                    <label>Giá: <span>*</span></label>
                    <input type="text" name="price" id="" class="text" value="<?php echo $topic->price; ?>">
                </div>

                <div class="field">
                    <label>Ản hiện giá: <span>*</span></label>
                    <select name="show_price">
                        <option value="1" <?php if($topic->show_price == 1 )echo 'selected' ?>>Hiện</option>
                        <option value="0" <?php if($topic->show_price == 0 )echo 'selected' ?>>Ẩn</option>
                    </select>
                </div>


                <div class="field">
                    <label>Thời hạn đăng: <span>*</span></label>
                    <input type="text" name="expire_date" id="expire_date" class="text " value="">
                </div>

                <div class="field">
                    <label>Cần Bán/ Mua ?: <span>*</span></label>
                    <?php
                    $product_type = array();
                    $product_type = Velacolib\Utility\Utility::getProductType();
                    ?>
                    <?php
                    foreach($product_type as $key => $p){
                        echo '  <div class="field">';
                        echo '<label>'.$p.'</label>';
                        ?>
                        <input type="radio" name="topic_type" value="<?php echo $key ?>" <?php if($key == $topic->topic_type) echo 'checked'; ?>>
                        <?php
                        echo '</div>';
                    }
                    ?>
                </div>

                <div class="field">
                    <label>Địa Điểm: <span>*</span></label>
                    <?php
                    $product_loc = array();
                    $product_loc = Velacolib\Utility\Utility::getLocationArray();
                    ?>
                    <select name="topic_location">

                        <?php
                        foreach($product_loc as $key => $l){
                            ?>
                            <option value="<?php echo $key ?>" <?php if($key == $topic->topic_location) echo 'selected'; ?>><?php echo $l; ?></option>
                        <?php
                        }
                        ?>
                    </select>
                </div>

                <div class="field">
                    <label>Danh mục: <span>*</span></label>
                    <?php
                    $cat = array();
                    $cat = Velacolib\Utility\Utility::getTopicCat()->getAll();
                    ?>
                    <select name="cat_id">
                        <?php
                        foreach($cat as $c){
                            ?>
                            <option <?php if($c->id == $topic->cat_id) echo 'selected'; ?> value="<?php echo $c->id ?>"><?php echo $c->title; ?></option>
                        <?php
                        }
                        ?>
                    </select>
                </div>

                <div class="field">
                    <label>Mô tả ngắn: <span>*</span></label>
                    <textarea name="short_description" class="text textarea"><?php  echo $topic->short_description; ?></textarea>

                    <input type="hidden" name="create_date" value="<?php echo $topic->create_date; ?>">
                </div>

                <div class="field">
                    <label>Nội dung : <span>*</span></label>
                    <textarea name="full_description" class="text textarea"><?php  echo $topic->full_description; ?></textarea>
                </div>

                <div class="field">
                    <input type="submit" id="send" value="Cập nhật">
                    <div class="loading"></div>
                </div>

            </form>

        </div>
    </div>
</div>
<script>
    $(document).ready(function(){
        $('.chosen-select').chosen();
        $('#file_upload').uploadify({
            'auto'     : true,
            'swf'      : '/templates/front/js/uploadify/uploadify.swf',
            'uploader' : '<?php echo $this->url('frontendtopic',array('action'=>'addtopicimg')) ?>',
            // 'formData'      : {'topic_id' : topic_id},
            'onUploadSuccess' : function(file, data, response) {
                $('#images_thumb').val(data);
                $('#images').attr('src',data);
                var content = '<div class="flickr_badge_image_upload two columns"><input type="hidden" name="gel[]" value="'+data+'"> <img src="'+data+'" ><input type="button" class="btn_set_thumbnail" thumb="'+data+'" value="Làm ảnh chính"><input type="button" class="btn_delete_img" value="Xóa"> </div>';
                $('#img_content').append(content);
            }
        });
        $('#expire_date').datepicker({ dateFormat: 'yy-mm-dd' }).val('<?php echo $topic->expire_date ?>');
    })
    $(document).on('click','.btn_set_thumbnail',function(){
        var str = $(this).attr('thumb');
        $('#images').attr('src',str);
        $('#images_thumb').val(str);
    });
    $(document).on('click','.btn_delete_img',function(){
        $(this).parent('.flickr_badge_image_upload').remove();

    });


</script>

<style>
    .swfupload{
        height: 35px!important;
    }
</style>